package com.open.spring.utils.validate.aop;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class RefIns {
	private static final RefIns instance = new RefIns();

	private RefIns() {
	}

	public static RefIns getInstance() {
		return instance;
	}

	/**
	 * 根据类和方法名得到方法
	 */
	public Method getMethodByClassAndName(Class<?> c, String methodName, int count) {
		Method[] methods = c.getDeclaredMethods();
		for (Method method : methods) {
			if ((method.getName().equals(methodName)) /*&& (method.getParameterCount()==count)*/) {
				return method;
			}
		}
		return null;
	}
	
	/**
	 * 根据方法和注解类 得到该方法的指定注解
	 */
	public Annotation getAnnotationByMethod(Method method, Class<?> annoClass) {
		Annotation[] annos = method.getAnnotations();
		for (Annotation annotation : annos) {
			if (annotation.annotationType() == annoClass) {
				return annotation;
			}
		}
		return null;
	}
}
